<?php
/**
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT		: Rubik Ultimate Framework
 * @version 	: 1.1
 * COPYRIGHT    : 2008
 * ------------------------------------------------------
 * 
 * Created on	:  Jun 15, 2008
 * 
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );

/**
 * Class that content all 
 * application infomation
 *
 */
RCoreImporter::cls( "sysObjects.SysTemplate" );

class SysApplication {
	
	/**
	 * Get the file for handel all process of site
	 *	Ex: D:www\framework\src\applications\news\news.back.app.php
	 * 
	 * @return String
	 */
	static function getApplicationMainFile() {
		$appName = SystemSite::getApplicationName ();
		return SYS_APP_PATH . $appName. DS . $appName . "." . SYS_WORK_ZONE . ".app.php";
	}
	
	/**
	 * Check if the request application is avaibale
	 *
	 * @return boolean
	 */
	static function isExistApplication() {
		return file_exists ( SysApplication::getApplicationMainFile () );
	}
	
	/**
	 * Import a class Form Controller
	 *
	 * @param string $classPath class path. it should be informat: "package.ClassName"
	 */
	static function importControllerCls($classPath) {
		$appName = SystemSite::getApplicationName ();
		$classPath = $appName . '.' . 'controllers.' . $classPath;
		return RAppImporter::cls( $classPath );
	}
	
	/**
	 * Get the System Application Name
	 *
	 * @return string
	 */
	static function getApplicationName() {
		return SystemSite::getApplicationName ();
	}
	
	/**
	 * Import a class Form Model
	 *
	 * @param string $classPath class path. it should be informat: "package.ClassName"
	 */
	static function importModelCls($classPath) {
		$appName = SystemSite::getApplicationName ();
		$classPath = $appName . '.' . 'models.' . $classPath;
		return RAppImporter::cls( $classPath );
	}
	
	/**
	 * Load Template Files
	 *
	 * @param string $classPath class path. it should be informat: "package.ClassName"
	 */
	static function loadTemplate($tplPath, $tplExt = ".tpl.html") {
		return SysTemplate::loadAppTemplate ( $tplPath, null, $tplExt );
	}
	
	/**
	 * Get Template Files Path
	 *
	 */
	static function getTemplatePath($tplPath, $tplExt = ".tpl.php") {
		return SysTemplate::getAppTemplatePath ( $tplPath, null, $tplExt );
	}
	
	/**
	 * Load CSS Files
	 *
	 * @param string $classPath class path. it should be informat: "package.ClassName"
	 */
	static function loadCSS($cssPath) {
		return SysTemplate::loadAppCSS ( $cssPath );
	}
	
	/**
	 * Load Javascript Files
	 *
	 * @param string $classPath class path. it should be informat: "package.ClassName"
	 */
	static function loadJS($jsPath) {
		return SysTemplate::loadAppJS ( $jsPath );
	}
	
	/**
	 * Import file inside current application
	 *
	 * @param string $filePath the file path from current application
	 */
	static function importFile($filePath) {
		$appName = SysApplication::getApplicationName ();
		$filePath = SYS_APP_PATH . $appName. DS . $filePath;
		AbstractRubikImporter::checkAndInclude ( $filePath );
	}
	
	/**
	 * Import the access file if it exists
	 *
	 */
	static function importAccessRight() {
		$name = SysApplication::getApplicationName ();
		$accessFile = SYS_APP_PATH . $name . DS . "$name.access.php";
		if (file_exists ( $accessFile )) {
			include ($accessFile);
		} else {
			RError::raiseWarning ( "403", "file: '$accessFile' not found" );
		}
	}
}
?>
